package com.next.androidintentlibrary;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.app.Context;

public class AlarmIntents {
    private Context context;
    Intent intent;

    private AlarmIntents(Context context)
    {
        this.context = context;
    }

    public static AlarmIntents from( Context context)
    {
        return new AlarmIntents(context);
    }

    public AlarmIntents openAlarms()
    {
        intent = new Intent();
        intent.setAction("android.intent.action.SHOW_ALARMS");
        return this;
    }

    public AlarmIntents createAlarm(String message, int hour, int minutes, boolean skipUi)
    {
        intent = new Intent();
        intent.setAction("android.intent.action.SET_ALARM");
        intent.setParam("android.intent.extra.alarm.MESSAGE", message);
        intent.setParam("android.intent.extra.alarm.HOUR", hour);
        intent.setParam("android.intent.extra.alarm.MINUTES", minutes);
        intent.setParam("android.intent.extra.alarm.SKIP_UI", skipUi);
        return this;
    }

    public AlarmIntents createAlarm(String message, int hour, int minutes, boolean skipUi, boolean vibrate)
    {
        intent = new Intent();
        intent.setAction("android.intent.action.SET_ALARM");
        intent.setParam("android.intent.extra.alarm.MESSAGE", message);
        intent.setParam("android.intent.extra.alarm.HOUR", hour);
        intent.setParam("android.intent.extra.alarm.MINUTES", minutes);
        intent.setParam("android.intent.extra.alarm.VIBRATE", vibrate);
        intent.setParam("android.intent.extra.alarm.SKIP_UI", skipUi);
        return this;
    }


    public AlarmIntents createAlarm(String message, int hour, int minutes, boolean skipUi, boolean vibrate, boolean isPm)
    {
        intent = new Intent();
        intent.setAction("android.intent.action.SET_ALARM");
        intent.setParam("android.intent.extra.alarm.MESSAGE", message);
        intent.setParam("android.intent.extra.alarm.HOUR", hour);
        intent.setParam("android.intent.extra.alarm.MINUTES", minutes);
        intent.setParam("android.intent.extra.alarm.VIBRATE", vibrate);
        intent.setParam("android.intent.extra.alarm.IS_PM", isPm);
        intent.setParam("android.intent.extra.alarm.SKIP_UI", skipUi);
        // TODO: add below overloads too
        // intent.putExtra(AlarmClock.EXTRA_DAYS, days);
        // intent.putExtra(AlarmClock.EXTRA_RINGTONE, ringtone);
        return this;
    }

    public Intent build()
    {
        return intent;
    }

    private void startAbility(Intent intent)
    {
        if (!(context instanceof Ability))
        {
            intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        }
        context.startAbility(intent,0);
    }

    public void show()
    {
        startAbility(build());
    }
}
